home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 32.8 KB | 1,249 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawSelection.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Henri Lamiraux
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef DRAWSELECTION_H
- #include "DrawSelection.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRAME_H
- #include "DrawFrame.h"
- #endif
-
- #ifndef SHAPES_H
- #include "Shapes.h"
- #endif
-
- #ifndef DRAWDEF_H
- #include "DrawDef.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWFACET_H
- #include "FWFacet.h"
- #endif
-
- #ifndef FWEVENTH_H
- #include "FWEventH.h"
- #endif
-
- #ifndef FWBORDER_H
- #include "FWBorder.h"
- #endif
-
- // ----- OPF Foundation Includes -----
-
- #ifndef BCSTOREU_H
- #include <BCStoreU.h>
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWGRAPHX_H
- #include "FWGraphx.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _DRAGDROP_
- #include <DragDrop.h>
- #endif
-
- #ifndef _XMPSESSN_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _STDPROPS_
- #include <StdProps.h>
- #endif
-
- #ifndef _INFO_
- #include <Info.h>
- #endif
-
- #ifndef _TRNSFORM_
- #include <Trnsform.h>
- #endif
-
- #ifndef _LINK_
- #include <Link.h>
- #endif
-
- #ifndef _LINKSRC_
- #include <LinkSrc.h>
- #endif
-
- #ifndef _PLFMTYPE_
- #include <PlfmType.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h> // for ff()
- #endif
-
- #pragma segment drawpart
-
- //==============================================================================
- // •• class CDrawSelection
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::CDrawSelection
- //------------------------------------------------------------------------------
-
- CDrawSelection::CDrawSelection():
- fDragRect(0,0,0,0)
- {
- fDrawPart = NULL;
- fUpdateShape = NULL;
- fProxyShapeCount = 0;
- fFrozenCount = 0;
- fCount = 0;
- fCollection = NULL;
- fSelectionShape = NULL;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::InitDrawSelection
- //------------------------------------------------------------------------------
-
- void CDrawSelection::InitDrawSelection(CDrawPart* drawPart)
- {
- InitSelection(drawPart, TRUE, TRUE); // Allow both publish and subscrib
-
- fDrawPart = drawPart;
- fCollection = new BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>;
-
- fSelectionShape = ::NewXMPShape();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::~CDrawSelection
- //------------------------------------------------------------------------------
-
- CDrawSelection::~CDrawSelection()
- {
- delete fUpdateShape;
- delete fSelectionShape;
- delete fCollection;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::WhichHandle
- //------------------------------------------------------------------------------
-
- CBaseShape* CDrawSelection::WhichHandle(FW_CFacet* facet, const FW_CPoint& mouse, short& whichHandle) const
- {
- whichHandle = 0;
-
- if (fCount != 0)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- CBaseShape *shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- whichHandle = shape->WhichHandle(facet, mouse);
- if (whichHandle != 0)
- return shape;
- ite.Next();
- }
- }
-
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DrawSelectionHandles
- //------------------------------------------------------------------------------
-
- void CDrawSelection::DrawSelectionHandles(FW_CFacet* facet, FW_Boolean turOn)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- while (!ite.IsDone())
- {
- (*ite.CurrentItem())->DrawShapeHandles(facet, turOn);
- ite.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DrawAllHandles
- //------------------------------------------------------------------------------
-
- void CDrawSelection::DrawAllHandles(FW_CFrame* frame, FW_Boolean turOn)
- {
- if (fCount != 0)
- {
- FW_CFrameFacetIterator ite(frame);
- FW_CFacet* facet;
- while (!ite.IsDone())
- {
- facet = ite.CurrentItem();
- FW_CGraphicContext gc(*facet);
- DrawSelectionHandles(facet, turOn);
- ite.Next();
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DrawHandles
- //------------------------------------------------------------------------------
-
- void CDrawSelection::DrawHandles(CBaseShape* shape, FW_Boolean turOn)
- {
- FW_CPartFrameIterator ite(fDrawPart, fDrawPart->GetMainPresentation());
- FW_CFrame* frame;
- while (!ite.IsDone())
- {
- frame = ite.CurrentItem();
- if (frame->IsActive())
- {
- FW_CFrameFacetIterator i(frame);
- FW_CFacet* facet;
- while (!i.IsDone())
- {
- facet = i.CurrentItem();
- FW_CGraphicContext gc(*facet);
- shape->DrawShapeHandles(facet, turOn);
- i.Next();
- }
- }
- ite.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::CloseSelection
- //------------------------------------------------------------------------------
-
- void CDrawSelection::CloseSelection()
- {
- CBaseShape *shape;
- while (!fCollection->IsEmpty())
- {
- shape = fCollection->First();
- DoRemove(shape);
- DrawHandles(shape, FALSE); // turn off
- }
-
- CalcDragRect();
- CalcUpdateShape();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::AddToSelection
- //------------------------------------------------------------------------------
-
- void CDrawSelection::AddToSelection(CBaseShape* newSelection, FW_Boolean drawHandles)
- {
- if (newSelection != NULL)
- {
- DoAdd(newSelection);
- if (drawHandles)
- DrawHandles(newSelection, TRUE); // Turn on
- }
-
- CalcDragRect();
- CalcUpdateShape();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::RemoveFromSelection
- //------------------------------------------------------------------------------
-
- void CDrawSelection::RemoveFromSelection(CBaseShape* shape, FW_Boolean drawHandles)
- {
- if (shape != NULL)
- {
- DoRemove(shape);
- if (drawHandles)
- DrawHandles(shape, FALSE); // Turn Off
- }
-
- CalcDragRect();
- CalcUpdateShape();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DoAdd
- //------------------------------------------------------------------------------
-
- void CDrawSelection::DoAdd(CBaseShape *shape)
- {
- shape->SelectShape(TRUE);
- fCollection->Append(shape);
- fCount++;
- if (shape->GetShapeType() == kProxyShape)
- fProxyShapeCount++;
- if (shape->IsFrozen())
- fFrozenCount++;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DoRemove
- //------------------------------------------------------------------------------
-
- void CDrawSelection::DoRemove(CBaseShape *shape)
- {
- shape->SelectShape(FALSE);
- fCollection->Remove(fCollection->Location(shape));
- fCount--;
- if (shape->GetShapeType() == kProxyShape)
- fProxyShapeCount--;
- if (shape->IsFrozen())
- fFrozenCount--;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DoClear
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::DoClear()
- {
- CBaseShape *shape;
- while (!fCollection->IsEmpty())
- {
- shape = fCollection->First();
- DoRemove(shape); // Remove from Selection list
- fDrawPart->DeleteShape(shape); // Remove from shape list
- }
-
- fDrawPart->ClipEmbeddedFrames(fDrawPart->GetMainPresentation());
- fDrawPart->InvalidateAllFrames(fDrawPart->GetMainPresentation(), NULL, fUpdateShape);
-
- CalcDragRect();
- CalcUpdateShape();
-
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::SelectAll
- //------------------------------------------------------------------------------
-
- void CDrawSelection::SelectAll()
- {
- DrawAllHandles(fDrawPart->GetActiveFrame(), FALSE);
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawPart->GetShapeList());
- CBaseShape *shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- if (!shape->IsSelected())
- DoAdd(shape);
- ite.Next();
- }
-
- DrawAllHandles(fDrawPart->GetActiveFrame(), TRUE);
-
- CalcDragRect();
- CalcUpdateShape();
-
- fDrawPart->SetTool(kSelectTool);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::IsEmpty
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsEmpty() const
- {
- return fCount == 0;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::IsSelectionOnlyOneProxyRun
- //------------------------------------------------------------------------------
-
- FW_CProxyRun* CDrawSelection::IsSelectionOnlyOneProxyRun() const
- {
- if (fCount == 1 && fProxyShapeCount == 1)
- {
- return ((CProxyShape*)fCollection->First())->GetProxyRun();
- }
-
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::ExternalizeSelection
- //------------------------------------------------------------------------------
-
- void CDrawSelection::ExternalizeSelection(XMPStorageUnit* storageUnit, FW_CFrame* commandFrame, XMPCloneKind cloneKind)
- {
- storageUnit->AddProperty(kXMPPropContents)->AddValue(GetPart()->GetContentPropertyValueType());
-
- // ----- Write number of shapes -----
- storageUnit->SetValue(sizeof(fCount), (XMPValue)&fCount);
-
- // ----- Write top left offset -----
- XMPCoordinate coordinate = -fDragRect.left;
- storageUnit->SetValue(sizeof(coordinate), (XMPValue)&coordinate);
- coordinate = -fDragRect.top;
- storageUnit->SetValue(sizeof(coordinate), (XMPValue)&coordinate);
-
- // ----- Write out the contents of the selection -----
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- while (!ite.IsDone())
- {
- (*ite.CurrentItem())->CloneTo(storageUnit, commandFrame, cloneKind);
- ite.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::InternalizeSelection
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::InternalizeSelection(XMPStorageUnit* storageUnit, XMPCloneKind cloneKind)
- {
- if (storageUnit->Exists(kXMPPropContents, GetPart()->GetContentPropertyValueType(), 0))
- {
- // ----- Close First the current selection -----
- CloseSelection();
-
- // ----- Focus on content property -----
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined,
- GetPart()->GetContentPropertyValueType(), (XMPValueIndex)0, kXMPPosUndefined);
-
- // ----- Read number of shapes -----
- unsigned long count;
- storageUnit->GetValue(sizeof(count), (XMPValue)&count);
-
- // ----- Read top left offset -----
- XMPCoordinate xTopLeft, yTopLeft;
- storageUnit->GetValue(sizeof(xTopLeft), (XMPValue)&xTopLeft);
- storageUnit->GetValue(sizeof(yTopLeft), (XMPValue)&yTopLeft);
-
- // ----- Then read in the new selection -----
- CBaseShape *after = NULL;
- for (unsigned short i = 0; i<count; i++)
- {
- unsigned short shapeType;
- CBaseShape* theShape = NULL;
- storageUnit->GetValue(sizeof(unsigned short), (XMPValue)&shapeType);
- theShape = fDrawPart->NewShape(shapeType);
-
- if (theShape)
- {
- theShape->CloneFrom(fDrawPart, storageUnit, cloneKind);
-
- if (after)
- fDrawPart->AddShapeAfter(after, theShape);
- else
- fDrawPart->AddShape(theShape);
- after = theShape;
-
- this->AddToSelection(theShape, FALSE);
- }
- }
-
- this->OffsetSelection(xTopLeft, yTopLeft);
-
- return TRUE;
- }
-
- return FALSE;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::EmbedSelection
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::EmbedSelection(XMPPart* xmpPart, XMPShape* frameShape)
- {
- CloseSelection();
-
- FW_CRect shapeRect;
- if (frameShape)
- {
- frameShape->GetBoundingBox(&shapeRect);
- shapeRect.Offset(ff(-shapeRect.left), ff(-shapeRect.top));
- }
- else
- {
- shapeRect.Set(ff(0), ff(0), ff(80), ff(80));
- }
-
- CProxyShape *proxyShape = fDrawPart->NewProxyShape(xmpPart, shapeRect, FALSE);
-
- AddToSelection(proxyShape, FALSE);
-
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DoPaste
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::DoPaste()
- {
- FW_Boolean result = FW_CSelection::DoPaste();
-
- if (result)
- AdjustSelectionAfterPaste();
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DoPasteWithLink
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::DoPasteWithLink()
- {
- FW_Boolean result = FW_CSelection::DoPasteWithLink();
-
- if (result)
- AdjustSelectionAfterPaste();
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::InsertNewPart
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::InsertNewPart()
- {
- FW_Boolean result = FW_CSelection::InsertNewPart();
-
- if (result)
- AdjustSelectionAfterPaste();
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::AdjustSelectionAfterPaste
- //------------------------------------------------------------------------------
-
- void CDrawSelection::AdjustSelectionAfterPaste()
- {
- fDrawPart->SetTool(kSelectTool);
-
- fDrawPart->InvalidateAllFrames(fDrawPart->GetMainPresentation(), NULL, fUpdateShape);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DoDroppedInSameFrame
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::DoDroppedInSameFrame(XMPStorageUnit* dropSU, FW_CFacet* facet,
- const FW_CPoint& originPoint, const FW_CPoint& dropPoint)
- {
- FW_UNUSED(dropSU);
-
- FW_CPoint delta = dropPoint - originPoint;
- if (delta != FW_CPoint(0,0))
- {
- facet->InvalidateAllFacets(fUpdateShape, FALSE);
- OffsetSelection(delta.x, delta.y);
- facet->InvalidateAllFacets(fUpdateShape, FALSE);
- }
-
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DoDrop
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::DoDrop(XMPStorageUnit* dropSU, FW_CFacet* facet, const FW_CPoint& originPoint, const FW_CPoint& dropPoint)
- {
- CloseSelection();
-
- FW_Boolean result = FW_CSelection::DoDrop(dropSU, facet, originPoint, dropPoint);
-
- if (result)
- {
- fDrawPart->SetTool(kSelectTool);
-
- FW_CPoint newOffset = dropPoint;
- FW_CPoint frameOffset(facet->GetWindowFrameTransform()->GetQDOffset());
-
- newOffset -= frameOffset;
- newOffset -= originPoint;
-
- FW_CRect box;
- fUpdateShape->GetBoundingBox(&box);
- FW_CPoint currentOffset = box.TopLeft();
- OffsetSelection(-currentOffset.x + newOffset.x, -currentOffset.y + newOffset.y);
-
- // ----- Invalidate -----
- fDrawPart->InvalidateAllFrames(fDrawPart->GetMainPresentation(), NULL, fUpdateShape);
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::DragFeedback
- //------------------------------------------------------------------------------
-
- void CDrawSelection::DragFeedback(FW_PlatformRegion dragRgn, short xDelta, short yDelta)
- {
- ::OffsetRgn(dragRgn, xDelta, yDelta);
- ::PaintRgn(dragRgn);
- ::OffsetRgn(dragRgn, -xDelta, -yDelta);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::Resize
- //------------------------------------------------------------------------------
-
- void CDrawSelection::Resize(FW_CGraphicContext* gc, short whichHandle, const FW_CPoint& firstPoint, XMPEventData event)
- {
- if (!::WaitMouseMoved(event->where))
- return;
-
- CBaseShape* anchorShape = GetAnchorShape();
-
- FW_CPoint handleCenter;
- anchorShape->GetHandleCenter(whichHandle, &handleCenter);
- anchorShape->DrawHandle(whichHandle); // erase handle
-
- // ----- Calcul delta between the mouse click and the
- // ----- handle center
- FW_CPoint delta = firstPoint - handleCenter;
-
- FW_CPoint currentLoc;
- FW_CPoint prevLoc = handleCenter;
-
- FW_Boolean firstMove = TRUE;
-
- XMPCoordinate penSize = anchorShape->GetPenSize();
-
- FW_CInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- FW_CStyle trackStyle(penSize);
-
- FW_CRect mapRect = anchorShape->GetBoundingBox();
- FW_CRect orgRect = mapRect;
- FW_Boolean eraseFlag = FALSE;
- FW_Boolean stillDown = TRUE;
-
- while (stillDown)
- {
- FW_SPlatformPoint qdLoc;
- ::GetMouse(&qdLoc);
- currentLoc = qdLoc;
- currentLoc -= delta;
-
- if (prevLoc != currentLoc)
- {
- if (eraseFlag)
- anchorShape->ResizeFeedback(gc, trackInk, trackStyle, orgRect, mapRect); // erase
-
- mapRect = orgRect;
- CalcMapRect(whichHandle, currentLoc, penSize, &mapRect);
-
- anchorShape->ResizeFeedback(gc, trackInk, trackStyle, orgRect, mapRect); // draw
-
- eraseFlag = TRUE;
- prevLoc = currentLoc;
- }
-
- stillDown = ::StillDown();
- }
-
- if (eraseFlag)
- anchorShape->ResizeFeedback(gc, trackInk, trackStyle, orgRect, mapRect); // Erase
-
- ::PenNormal();
-
- if (firstPoint != currentLoc)
- {
- FW_CFacet* facet = FW_CFacet::XMPtoFWFacet(gc->GetXMPFacet());
-
- facet->InvalidateAllFacets(fUpdateShape, FALSE);
- MapSelection(orgRect, mapRect);
- facet->InvalidateAllFacets(fUpdateShape, FALSE);
-
- // ----- Clip all embedding frames -----
- ((FW_CEmbeddingPart*)facet->GetFrame()->GetPart())->ClipEmbeddedFrames(facet->GetFrame()->GetIdentifier());
-
- SelectionChanged();
- }
- else
- {
- anchorShape->DrawHandle(whichHandle); // redraw the handle
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::CalcMapRect
- //------------------------------------------------------------------------------
-
- void CDrawSelection::CalcMapRect(short whichHandle, const FW_CPoint& currentPos, XMPCoordinate penSize, FW_CRect* mapRect)
- {
- switch (whichHandle)
- {
- case kInTopLeftCorner:
- mapRect->left = currentPos.x;
- mapRect->top = currentPos.y;
- break;
- case kInTopRightCorner:
- mapRect->right = currentPos.x+1;
- mapRect->top = currentPos.y;
- break;
- case kInBottomLeftCorner:
- mapRect->left = currentPos.x;
- mapRect->bottom = currentPos.y+1;
- break;
- case kInBottomRightCorner:
- mapRect->right = currentPos.x+1;
- mapRect->bottom = currentPos.y+1;
- break;
- }
-
- if (mapRect->left > mapRect->right)
- {
- switch (whichHandle)
- {
- case 1:
- case 3:
- mapRect->right -= penSize;
- break;
- case 2:
- case 4:
- mapRect->left += penSize;
- break;
- }
- }
- if (mapRect->top > mapRect->bottom)
- {
- switch (whichHandle)
- {
- case 1:
- case 2:
- mapRect->bottom -= penSize;
- break;
- case 3:
- case 4:
- mapRect->top += penSize;
- break;
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::CalcDragRect
- //------------------------------------------------------------------------------
-
- void CDrawSelection::CalcDragRect()
- {
- fDragRect.Clear();
-
- if (fCount == 0)
- return;
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- FW_Boolean first = TRUE;
- while (!ite.IsDone())
- {
- FW_CRect tempRect = (*ite.CurrentItem())->GetBoundingBox();
- if (first)
- fDragRect = tempRect;
- else
- fDragRect |= tempRect;
- first = FALSE;
- ite.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::CalcDragRgn
- //------------------------------------------------------------------------------
-
- XMPRgnHandle CDrawSelection::CalcDragRgn(FW_CFacet* facet)
- {
- FW_CGraphicContext gc(*facet);
-
- CBaseShape* anchorShape = GetAnchorShape();
- XMPRgnHandle dragRgn = ::NewRgn();
-
- FW_PlatformRegion tempRgn = ::NewRgn();
-
- if (fCount > 1)
- {
- FW_SPlatformRect qdRect = fDragRect;
- ::RectRgn(dragRgn, &qdRect);
- ::CopyRgn(dragRgn, tempRgn);
- ::InsetRgn(tempRgn, 1, 1);
- ::DiffRgn(dragRgn, tempRgn, dragRgn);
- }
-
- anchorShape->GetDragRgn(&gc, tempRgn);
- ::UnionRgn(dragRgn, tempRgn, dragRgn);
-
- ::DisposeRgn(tempRgn);
-
- return dragRgn;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::CalcUpdateShape
- //------------------------------------------------------------------------------
-
- void CDrawSelection::CalcUpdateShape()
- {
- delete fUpdateShape;
- fUpdateShape = ::NewXMPShape();
-
- if (fCount == 0)
- return;
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- XMPShape* tempShape = ::NewXMPShape();
- while (!ite.IsDone())
- {
- (*ite.CurrentItem())->GetUpdateShape(tempShape);
- fUpdateShape->Union(tempShape);
- ite.Next();
- }
- delete tempShape;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::MapSelection
- //------------------------------------------------------------------------------
-
- void CDrawSelection::MapSelection(const FW_CRect& srcRect, const FW_CRect& dstRect)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- while (!ite.IsDone())
- {
- (*ite.CurrentItem())->MapShape(srcRect, dstRect);
- ite.Next();
- }
-
- fDrawPart->ClipEmbeddedFrames(fDrawPart->GetMainPresentation());
-
- CalcDragRect();
- CalcUpdateShape();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::OffsetSelection
- //------------------------------------------------------------------------------
-
- void CDrawSelection::OffsetSelection(XMPCoordinate xDelta, XMPCoordinate yDelta)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- while (!ite.IsDone())
- {
- (*ite.CurrentItem())->OffsetShape(xDelta, yDelta);
- ite.Next();
- }
-
- fDrawPart->ClipEmbeddedFrames(fDrawPart->GetMainPresentation());
-
- CalcDragRect();
- CalcUpdateShape();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::SelectWithRectangle
- //------------------------------------------------------------------------------
-
- void CDrawSelection::SelectWithRectangle(FW_CFacet* facet, const FW_CPoint& anchorPoint, XMPEventData event)
- {
- CRectShape rectShape; // Create a rect shape on the stack
-
- char framePat[8] = {0xCC, 0x66, 0x33, 0x99, 0xCC, 0x66, 0x33, 0x99};
- FW_CStyle trackStyle(ff(1), framePat);
-
- FW_CGraphicContext gc(*facet);
- if (rectShape.Track(&gc, trackStyle, anchorPoint, event))
- {
- FW_Boolean isShift = IsShiftKeyPressed();
- FW_CRect selectRect = rectShape.GetBoundingBox();
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawPart->GetShapeList());
- CBaseShape *shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- if (shape->InSelectionRect(selectRect))
- {
- if (shape->IsSelected())
- {
- if (isShift)
- {
- DoRemove(shape);
- DrawHandles(shape, FALSE); // Turn Off
- }
- }
- else
- {
- DoAdd(shape);
- DrawHandles(shape, TRUE); // Turn on
- }
- }
- else if (shape->IsSelected() && !isShift)
- {
- DoRemove(shape);
- DrawHandles(shape, FALSE); // Turn Off
- }
- ite.Next();
- }
- CalcDragRect();
- CalcUpdateShape();
- }
- else
- {
- CloseSelection();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::ChangeSelectionPenSize
- //------------------------------------------------------------------------------
-
- void CDrawSelection::ChangeSelectionPenSize(XMPCoordinate newPenSize)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- FW_CStyle newStyle = shape->GetPenStyle()->Copy();
- newStyle->SetPenSize(newPenSize);
- shape->SetPenStyle(newStyle);
- this->RedrawShape(shape);
- ite.Next();
- }
-
- fDrawPart->ClipEmbeddedFrames(fDrawPart->GetMainPresentation());
-
- SelectionChanged();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::ChangeSelectionFillColor
- //------------------------------------------------------------------------------
-
- void CDrawSelection::ChangeSelectionFillColor(const FW_CColor& color)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- FW_CInk newInk = shape->GetBrushInk()->Copy();
- newInk->SetForeColor(color);
- shape->SetBrushInk(newInk);
- this->RedrawShape(shape);
- ite.Next();
- }
-
- SelectionChanged();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::ChangeSelectionPenColor
- //------------------------------------------------------------------------------
-
- void CDrawSelection::ChangeSelectionPenColor(const FW_CColor& color)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- FW_CInk newInk = shape->GetPenInk()->Copy();
- newInk->SetForeColor(color);
- shape->SetPenInk(newInk);
- this->RedrawShape(shape);
- ite.Next();
- }
-
- SelectionChanged();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::ChangeSelectionFillFrame
- //------------------------------------------------------------------------------
-
- void CDrawSelection::ChangeSelectionFillFrame(unsigned short newFillFrame)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- shape->SetFrameFillStyle(newFillFrame);
- this->RedrawShape(shape);
- ite.Next();
- }
-
- fDrawPart->ClipEmbeddedFrames(fDrawPart->GetMainPresentation());
-
- SelectionChanged();
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::RedrawShape
- //------------------------------------------------------------------------------
-
- void CDrawSelection::RedrawShape(CBaseShape *shape)
- {
- XMPShape* invalidShape = ::NewXMPShape();
- shape->GetUpdateShape(invalidShape);
- fDrawPart->InvalidateAllFrames(fDrawPart->GetMainPresentation(), NULL, invalidShape);
- delete invalidShape;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::SetFrozen
- //------------------------------------------------------------------------------
-
- void CDrawSelection::SetFrozen(FW_Boolean state)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- if (shape->SetFrozen(state))
- {
- state ? fFrozenCount++ : fFrozenCount--;
- }
- ite.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::NewPublishLink
- //------------------------------------------------------------------------------
-
- FW_CPublishLink* CDrawSelection::NewPublishLink(XMPChangeID changeID)
- {
- return new CDrawPublishLink(changeID, this);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::NewSubscribLink
- //------------------------------------------------------------------------------
-
- FW_CSubscribLink* CDrawSelection::NewSubscribLink(XMPLink *xmpLink)
- {
- return new CDrawSubscribLink(xmpLink, this);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::SelectionChanged
- //------------------------------------------------------------------------------
-
- void CDrawSelection::SelectionChanged()
- {
- BC_TDynamicCollection<CDrawPublishLink*, BC_CUnmanaged> temp(5); // Assume an average of 5 shapes
- BC_TCollectionActiveIterator<CDrawPublishLink*> tempIte(temp);
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- if (shape->IsPublished())
- {
- FW_Boolean add = TRUE;
- tempIte.Reset();
- CDrawPublishLink* link;
- while (!tempIte.IsDone())
- {
- link = *tempIte.CurrentItem();
- if (shape->GetPublishLink() == link)
- {
- add = FALSE;
- break;
- }
- tempIte.Next();
- }
- if (add)
- temp.Append(shape->GetPublishLink());
- }
- ite.Next();
- }
-
- tempIte.Reset();
- while (!tempIte.IsDone())
- {
- (*tempIte.CurrentItem())->ContentChanged(fDrawPart->GetSession()->UniqueChangeID());
- tempIte.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::IsSelectionPublishable
- //------------------------------------------------------------------------------
- // We don't allow linking if one of the shape is already published
-
- FW_Boolean CDrawSelection::IsSelectionPublishable()
- {
- FW_Boolean result = TRUE;
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fCollection);
- while (!ite.IsDone())
- {
- if ((*ite.CurrentItem())->IsPublished())
- {
- result = FALSE;
- break;
- }
- ite.Next();
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSelection::GetSelectionShape
- //------------------------------------------------------------------------------
-
- XMPShape* CDrawSelection::GetSelectionShape()
- {
- FW_CRect selectionRect(fDragRect);
- selectionRect.Offset(-selectionRect.left, -selectionRect.top);
- fSelectionShape->SetRectangle(&selectionRect);
- return fSelectionShape;
- }
-
- //==============================================================================
- // •• class CDrawPublishLink
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • CDrawPublishLink::CDrawPublishLink
- //------------------------------------------------------------------------------
-
- CDrawPublishLink::CDrawPublishLink(XMPChangeID changeID, CDrawSelection *drawSelection) :
- FW_CPublishLink(changeID)
- {
- fDrawSelection = drawSelection;
- fCollection = NULL;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPublishLink::~CDrawPublishLink
- //------------------------------------------------------------------------------
-
- CDrawPublishLink::~CDrawPublishLink()
- {
- delete fCollection;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPublishLink::Publish
- //------------------------------------------------------------------------------
-
- void CDrawPublishLink::Publish()
- {
- fCollection = new BC_TDynamicCollection<CBaseShape*, BC_CUnmanaged>(kChunkSize);
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawSelection->GetSelectionCollection());
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- fCollection->Append(shape);
- shape->SetPublishLink(this);
- ite.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPublishLink::GetPublishFormat
- //------------------------------------------------------------------------------
-
- XMPValueType CDrawPublishLink::GetPublishFormat()
- {
- return kPublishFormat;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPublishLink::ExternalizeLinkContent
- //------------------------------------------------------------------------------
-
- void CDrawPublishLink::ExternalizeLinkContent(XMPStorageUnit* linkSU)
- {
- fDrawSelection->ExternalizeSelection(linkSU, NULL, kXMPCloneCopy);
- }
-
- //==============================================================================
- // •• class CDrawSubscribLink
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • CDrawSubscribLink::CDrawSubscribLink
- //------------------------------------------------------------------------------
-
- CDrawSubscribLink::CDrawSubscribLink(XMPLink *xmpLink, CDrawSelection *drawSelection) :
- FW_CSubscribLink(xmpLink)
- {
- fDrawSelection = drawSelection;
- fCollection = NULL;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawSubscribLink::~CDrawSubscribLink
- //------------------------------------------------------------------------------
-
- CDrawSubscribLink::~CDrawSubscribLink()
- {
- delete fCollection;
- }
-
- //---------------------------------------------------------------------------------------
- // • CDrawSubscribLink::Subscrib
- //---------------------------------------------------------------------------------------
-
- void CDrawSubscribLink::Subscrib()
- {
- fCollection = new BC_TDynamicCollection<CBaseShape*, BC_CUnmanaged>(kChunkSize);
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawSelection->GetSelectionCollection());
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- fCollection->Append(shape);
- shape->SetSubscribLink(this);
- ite.Next();
- }
- }
-
-